import Vue from 'vue';
import MessageBox from './index.vue';

let newInstance;
const msgBoxInstence = Vue.extend(MessageBox)

// 动态创建组件并添加到页面上
const initInstance = () => {
    newInstance = new msgBoxInstence();
    document.body.append(newInstance.$mount().$el)
}

export default (options) => {
    if (!newInstance) {
        initInstance(options); // 挂载
    }
    // 合并对象 这里是把options与pros合并的关键
    Object.assign(newInstance, options);
    return newInstance.showBox(() => {
        newInstance = null;
    })
}